// 使用transform把文件映射为它的行数

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int count_lines(const string& file) {
    ifstream in(file);
    return count(
        istreambuf_iterator<char>(in),
        istreambuf_iterator<char>(),
        '\n'
    );
}

vector<int> count_lines_in_files(vector<string>& files) {
    vector<int> results(files.size());
    transform(
        files.begin(), files.end(), // 源
        results.begin(),            // 目标
        count_lines         // 使用这个函数进行转换
    );
    return results;
}

int main() {
    vector<string> files{"ch01/1_3.cpp"};
    for (int line_count : count_lines_in_files(files)) {
        cout << line_count << "\n";
    }
}
